package com.xbts.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xbts.system.mapper.CnSettingHomePicMapper;
import com.xbts.system.domain.CnSettingHomePic;
import com.xbts.system.service.ICnSettingHomePicService;

/**
 * 首页轮播图列Service业务层处理
 * 
 * @author xbts
 * @date 2023-09-05
 */
@Service
public class CnSettingHomePicServiceImpl  extends ServiceImpl<CnSettingHomePicMapper, CnSettingHomePic> implements ICnSettingHomePicService {

    /**
     * 查询首页轮播图列列表
     *
     * @return 首页轮播图列
     */
    @Override
    public List<CnSettingHomePic> selectCnSettingHomePicList() {
        CnSettingHomePic cnSettingHomePic = new CnSettingHomePic();
        QueryWrapper<CnSettingHomePic> queryWrapper = cnSettingHomePic.queryWrapper();
        queryWrapper.orderByAsc("sort");
        return list(queryWrapper);
    }

    /**
     * 查询首页轮播图列
     *
     * @param id 首页轮播图列主键
     * @return 首页轮播图列
     */
    @Override
    public CnSettingHomePic selectCnSettingHomePicById(String id) {
        return getById(id);
    }

    /**
     * 新增首页轮播图列
     *
     * @param cnSettingHomePic 首页轮播图列
     * @return 结果
     */
    @Override
    public boolean insertCnSettingHomePic(CnSettingHomePic cnSettingHomePic) {
        long count = count();
        // 最多4张
        if (count >= 4) {
            throw new RuntimeException("最多4张轮播图片，请先删除再添加");
        }
        return save(cnSettingHomePic);
    }

    /**
     * 修改首页轮播图列
     *
     * @param cnSettingHomePic 首页轮播图列
     * @return 结果
     */
    @Override
    public boolean updateCnSettingHomePic(CnSettingHomePic cnSettingHomePic) {
        return updateById(cnSettingHomePic);
    }

    /**
     * 批量删除首页轮播图列
     *
     * @param ids 需要删除的首页轮播图列主键
     * @return 结果
     */
    @Override
    public boolean deleteCnSettingHomePicByIds(List<String> ids) {
        return removeBatchByIds(ids);
    }

    /**
     * 删除首页轮播图列信息
     *
     * @param id 首页轮播图列主键
     * @return 结果
     */
    @Transactional
    @Override
    public boolean deleteCnSettingHomePicById(String id) {
      return removeById(id);
    }

}
